﻿/*----------------------------------------------------------------
 * 
 * 版权所有：Copyright (C) 2013
 * 
 * 文件名：UnitOfWork.cs
 * 文件功能描述：
 * 
 * 
 * 作 者：zhangq
 * 邮 箱：ifunnyface@outlook.com
 * 日 期：2013-01-23 09:21:28
 * 
 * 
 * 修改标识： Author
 * 修改描述： 相关描述
 * 
 * ---------------------------------------------------------------- */

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;

namespace Manager.Infrastructure
{

    /// <summary>
    /// 
    /// </summary>
    public class UnitOfWork : IUnitOfWork
    {

        private readonly IDbContextFactory databaseFactory;
        private bool disposed;
        private EFDBContext dataContext;

        public UnitOfWork(IDbContextFactory databaseFactory)
        {
            this.databaseFactory = databaseFactory;
        }

        protected EFDBContext DataContext
        {
            get { return dataContext ?? (dataContext = databaseFactory.GetDbContext()); }
        }


        public void Commit()
        {
            DataContext.Commit();
        }


        //public void Dispose()
        //{
        //    Dispose(true);
        //    GC.SuppressFinalize(this);
        //}

        //protected virtual void Dispose(bool disposing)
        //{
        //    if (!disposed)
        //    {
        //        if (disposing)
        //        {
        //            dataContext.Dispose();
        //        }
        //    }
        //    disposed = true;
        //}


    }

}